package com.example.mymvvmdemo.net.presenter;


import com.example.mymvvmdemo.MyApplication;
import com.example.mymvvmdemo.net.model.IModel;
import com.example.mymvvmdemo.net.model.PutBodyModel;
import com.example.mymvvmdemo.net.view.IView;
import com.example.mymvvmdemo.utils.LogUtils;

import java.util.HashMap;

import okhttp3.RequestBody;

/**
 * 只具有一个body参数的post请求统一presenter
 */
public class PutBodyPresenter implements IModel.PutBodyModel {

    private PutBodyModel putBodyModel = new PutBodyModel(this);

    private IView.PutBodyView putBodyView;

    public PutBodyPresenter(IView.PutBodyView putBodyView) {
        this.putBodyView = putBodyView;
    }

    public void startLoadPutBody(String url, HashMap<String, String> hashMap, String type) {
        putBodyModel.startLoadPutBody(url, MyApplication.getAuthToken(), hashMap, type);
    }


    //回调给view
    @Override
    public void loadPutBodySuccess(String result, String type, int code) {
        LogUtils.d("load put body success type:" + type + ",result:" + result);
        LogUtils.printJson(result, type);
        putBodyView.loadPutBodySuccess(result, type, code);
    }

    @Override
    public void loadPutBodyFail(String message, String type) {
        LogUtils.d("load put body success type:" + type + ",message:" + message);
        putBodyView.loadPutBodyFail(message, type);
    }

    @Override
    public void loadPutBodyAccountError(int code) {
        LogUtils.d("load put body account error code :" + code);
        putBodyView.loadPutBodyAccountError(code);
    }

    @Override
    public void loadPutBodyNetWorkError(String message) {
        LogUtils.d("load put body network error :" + message);
        putBodyView.loadPutBodyNetWorkError();
    }

}
